'''
Created on Apr 14, 2011

@author: yc30v1m
'''
from logging import getLogger
from types import TypeType
from library.handlers.TestCase import TestCase
from includes.CountValidation import CountValidation #@UnusedImport
from includes.PwsApiValidation import PwsApiValidation #@UnusedImport

log = getLogger(__name__)

class TestCaseFactory(object):
    '''
    classdocs
    '''
    
    currentTestCase = None
    reader = None
    def __init__(self,currentTestCaseId, reader):
        #print 'TestCase Factory', str(currentTestCaseId)
        self.currentTestCase = str(currentTestCaseId)
        self.reader = reader
        
    def executeTestCase(self,testCaseExecutionType = None):
        try:
            print " Current TC Type : " , testCaseExecutionType
            if testCaseExecutionType == None:
                testCaseExecutionType = "CountValidation"
            TestCaseClasses = [j for (i,j) in globals().iteritems() if isinstance(j, TypeType) and issubclass(j, TestCase)] #@UnusedVariable
            for TestCaseClass in TestCaseClasses:
                if TestCaseClass.supportedExecutionTypes(testCaseExecutionType):
                    print " And is Supported : ", testCaseExecutionType
                    return TestCaseClass(self.currentTestCase, self.reader)
            #if research was unsuccessful, raise an error
        except Exception as e:
            print 'No TestCase containing "%s".' % testCaseExecutionType
            print "Exception Occured : ", str(e)